package com.woniuxy.jiapei.util;

import com.mysql.fabric.xmlrpc.base.Data;
import net.bytebuddy.implementation.InvokeDynamic;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaDate {
    Date date = new Date();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public TimePojo javaDate(String d1, String d2) throws ParseException {
        TimePojo timePojo = new TimePojo();
        Date date1 = df.parse(d1);
        Date date2 = df.parse(d2);
        long diff = date2.getTime() - date1.getTime();
        long days = diff / (1000 * 60 * 60 * 24);
        long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
        System.out.println(minutes);
        String t1 = days + "天" + hours + "小时" + minutes + "分钟";
        double t2;
        if (minutes >= 30) {
             t2 = (days * 24) + hours + 1;
        }else {
             t2 = (days * 24) + hours;
        }

        timePojo.setDate2(t2);
        System.out.println(t1 + "   ------     " + t2);
        return timePojo;
    }

    public static void main(String[] args) throws ParseException {
        String d1 = "2018-03-26 13:08:40";
        String d2 = "2018-03-27 18:38:40";
        JavaDate javaDate = new JavaDate();
        javaDate.javaDate(d1, d2);
    }
}
